package org.john.javalib;

import org.apache.commons.codec.digest.DigestUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by adsame on 17-3-9.
 */
public class StringTest {

    public static void main(String args[]) {
        String s1 = "aaa";
        String s2 = "aaa";
        System.out.println(s1 == s2);
        String p[] = {"?", "??", "???", "a?", "??a", ""};
        for (int i = 0; i < p.length; ++i) {
            boolean match = p[i].matches("^\\?+$");
            System.out.println("str:" + p[i] + ", result:" + match);
        }
        String pattern = "?a|b?b??b";
//        pattern = "?ATC??TC?ATC";
        String substring[] = pattern.split("\\?+|\\|");
        int startIdx = 0;
        for (int i = 0; i < substring.length; ++i) {
            int idx = pattern.indexOf(substring[i], startIdx) + substring[i].length();
            System.out.println(pattern.matches(substring[i]));
            System.out.println("str:" + substring[i] + ",start idx:" + startIdx + ", idx:" + idx+","+substring[i].getBytes());
            startIdx = idx;
        }
        String s = "abc\tbt\tc";
        System.out.println(s);
        String split[] = s.split("\t");
        System.out.println(split[1]);
        String a = "'s/<RollingRandomAccessFile name=\\\"total\\\"/<RollingRandomAccessFile name=\\\"videoLoggerFile\\\" fileName=\\\"\\/data\\/algorithm\\/log\\/{$adx}-bidder\\/video.log\\\"\\n                filePattern=\\\"\\/data\\/algorithm\\/log\\/{$adx}-bidder\\/video.log.%d{yyyy-MM-dd-HH}\\\" immediateFlush=\\\"false\\\">\\n            <PatternLayout pattern=\\\"[%-d{yyyy-MM-dd HH:mm:ss}] %-5p %m%n\\\"\\/>\\n            <Policies>\\n                <TimeBasedTriggeringPolicy interval = \\\"1\\\" modulate = \\\"true\\\"/>\\n            <\\/Policies>\\n        <\\/RollingRandomAccessFile>\\n        <RollingRandomAccessFile name=\\\"total\\\"/'";
        System.out.println(a.substring(465));
        String win = "http://dspwin.i-same.com/iqiyi/?ext=c29sdXRpb25JRD00MDAwMTc4NDMmaXFpeWlVSUQ9NzUxZDJhMTllNjk3OWY4NDAyOWYxZWNlN2U1ZTNmOTUmd2luX2RhdGE9ZmFsc2UsaXFpeWlfMGVhZDBkMWY2ZDRmODUxNmNiODA3NGJmYjY2MTRkOWU&price=${SETTLEMENT}&z=dsp&la=0&si=1&cg=1&c=1&ci=600000597&or=500007625&l=400017843&bg=1&b=400017843&_ext=eJyNjj1KBEEQhatrQCZUExcXREXEsKqn_4q9xWYmLjPT3TDo_hiIiBfwPgbGhp7AC5h4i-3ZBWMrKIrHe_W96eQNJSiomN0lnHvLUbcsyYmXHAxpyZz65JNNTRaL4v_hqrhpatjPBYot3zUDSjMeemQRINudZXZ19FpUGdUwLgHFx3A4PA4vw2K57oaHtGg3m4pJanCnt9O7-Ycyu-zJ99c7Bg1o9Q1c7xOU2kiRs4smB8uu7wJ50-XOOTZRUmFRwdBfQYVeq1JOlMIQajh4Wt2v1s9oqThUf_b58wtbb6U8pA";
        System.out.println(win.length());
        System.out.println(DigestUtils.md5Hex("020000000000"));
        Integer is[] = new Integer[0];
        System.out.println(is.length);
        for (Integer i : is) {
            System.out.println("in for:" + i);
        }
        List<Integer> list = Arrays.asList(is);
        System.out.println(list.size());
        String template = "http://carat.clientsolutions.cn/c=1,1,2&bidid=$(carat_bidid)&ep=$(carat_price)&adx=" +
                "$(carat_adx)&url=$(carat_url)&app=$(carat_app)&deviceid=$(carat_deviceid)&userid=$(carat_userid)" +
                "&ip=$(carat_ip)";
        String bidId = "";
        System.out.println(template);
//        template = template.replaceAll("\\$\\(carat_bidid\\)", bidId);
        System.out.println(template);
        bidId = "abcd";
        template = template.replaceAll("\\$\\(carat_bidid\\)", bidId);
        System.out.println(template);
        String json = "[{\"time\":14,\"url\":\"http:\\/\\/sammix.adsame.com\\/c?z=sammix&la=0&si=558&ci=7555&cg=521&c=15271&or=20205&l=98274&bg=98889&b=91882&u=\"},{\"time\":14,\"url\":\"http:\\/\\/t.cr-nielsen.com\\/hat?_t=i&type=imp&hat_id=MTM3JjI2MSY4MTAwMTQ4OCYxMTMyODAyJjMyMTE1NzkzJmcs&_z=m&OS=__OS__&IMEI=__IMEI__&MAC=__MAC__&IDFA=__IDFA__&OPENUDID=__OPENUDID__&ANDROIDID=__ANDROIDID__&rnd=49041468\"}]";
        json = "[{\\\"time\\\":14,\\\"url\\\":\\\"http:\\\\/\\\\/sammix.adsame.com\\\\/c?z=sammix&la=0&si=558&ci=7555&cg=521&c=15271&or=20205&l=98274&bg=98889&b=91882&u=\\\"},{\\\"time\\\":14,\\\"url\\\":\\\"http:\\\\/\\\\/t.cr-nielsen.com\\\\/hat?_t=i&type=imp&hat_id=MTM3JjI2MSY4MTAwMTQ4OCYxMTMyODAyJjMyMTE1NzkzJmcs&_z=m&OS=__OS__&IMEI=__IMEI__&MAC=__MAC__&IDFA=__IDFA__&OPENUDID=__OPENUDID__&ANDROIDID=__ANDROIDID__&rnd=49041468\\\"}]";
        System.out.println(json);
        System.out.println(json.replaceAll("\\\\", ""));
        String str = "s/<AsyncLogger name=\\\"kafka.producer/<AsyncLogger name=\\\"org.mongodb\\\" level=\\\"warn\\\" additivity=\\\"false\\\">\\n            <AppenderRef ref=\\\"log4jFile\\\"/>\\n        <\\/AsyncLogger>\\n        <AsyncLogger name=\\\"com.datastax.driver.core\\\" level=\\\"warn\\\" additivity=\\\"false\\\">\\n            <AppenderRef ref=\\\"log4jFile\\\"/>\\n        <\\/AsyncLogger>\\n        <AsyncLogger name=\\\"kafka.producer/";
        System.out.println(str.substring(150));
    }
}
